const mongoose = require('mongoose');

const healthSchema = new mongoose.Schema({
  userId: {
    type: String,
    required: true,
    match: /^user\d{3}$/
  },
  type: {
    type: String,
    required: true,
    enum: ['steps', 'temperature', 'weight', 'heartRate', 
          'bloodPressure', 'bloodSugar', 'bloodOxygen', 'bloodLipids']
  },
  value: mongoose.Schema.Types.Mixed,
  status: {
    type: String,
    enum: ['正常', '偏低', '危险', '未知']
  },
  date: {
    type: String,
    required: true,
    validate: {
      validator: v => /^\d{2}-\d{2} \d{2}:\d{2}$/.test(v),
      message: '日期格式必须为 MM-DD HH:mm'
    }
  }
});

module.exports = mongoose.model('Health', healthSchema);